<template>
  <div align="center">
    <table border="1" cellspacing="0">
      <tr>
        <td>名称</td>
        <td>价格</td>
        <td>操作</td>
      </tr>
      <tr v-for="i in glist">
        <td>{{ i.name }}</td>
        <td>{{ i.price }}</td>
        <td @click="buy(i.id)">购买</td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      glist: [],
      userid: localStorage.getItem('userid')
    }
  },
  methods: {
    getlist() {
      this.axios.get('')
        .then(res => {
          this.glist = res.data.list
        })
    },
    buy(id) {
      if (this.userid) {

      } else {
        this.$router.push({'path': '/login'})
      }
    }
  },
  mounted() {
    this.getlist()
  }
}
</script>

<style scoped>

</style>
